package com.kapil.framework.email;


/**
 * Factory for creating email processors.
 */
public final class EmailDispatcherFactory
{
    public static final String DUMMY_DISPATCHER = "DUMMY_DISPATCHER";
    
    public static final String DIRECT_DISPATCHER = "DIRECT_DISPATCHER";

    private static final EmailDispatcherFactory INSTANCE = new EmailDispatcherFactory();


    /**
     * Made private to enforce <code>Singleton</code> pattern.
     */
    public static EmailDispatcherFactory getInstance()
    {
        return INSTANCE;
    }


    /**
     * Creates an object implementing {@link IEmailDispatcher}.
     * 
     * @param emailTypeName A {@link java.lang.String} containing name of the email for which a processor is required.
     * @return An {@link IEmailDispatcher} object.
     */
    public IEmailDispatcher getDispatcher(EmailServer server, String emailTypeName)
    {
        IEmailDispatcher emailDispatcher = null;
        
        if (emailTypeName.equals(DUMMY_DISPATCHER))
        {
            emailDispatcher = new DummyEmailDispatcher();
        }
        else if (emailTypeName.equals(DIRECT_DISPATCHER))
        {
            emailDispatcher = new DirectEmailDispatcher(server);
        }
        else
        {
            emailDispatcher = new DirectEmailDispatcher(server);
        }

        return emailDispatcher;
    }
}
